package com.lime49.lockcrypt.ui;

import java.awt.*;
import javax.swing.*;

/**
 *
 */
public class PasswordDialog {
    public static String ShowPasswordDialog(Frame owner, String message, String caption) {
        JPanel pnl = new JPanel();
            pnl.setLayout(new BoxLayout(pnl, BoxLayout.PAGE_AXIS));
        JLabel lbl = new JLabel(message);
            pnl.add(lbl);
            lbl.setAlignmentX(Component.LEFT_ALIGNMENT);
            lbl.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 4));
        JPasswordField pw = new JPasswordField(30);
            pnl.add(pw);
        if(JOptionPane.showOptionDialog(owner, pnl, caption, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) {
            return new String(pw.getPassword());
        } else {
            return null;
        }
    }
}
